//
//  GJHomeViewController.m
//  GJLifeSimple
//
//  Created by 杨帆 on 16/6/17.
//  Copyright © 2016年 GoodJob. All rights reserved.
//

#import "GJHomeViewController.h"
#import "CZSlideView.h"
#import "GJLoginViewController.h"

@interface GJHomeViewController ()

static  NSString *cellId = @"cellId";
@interface GJHomeViewController () <UITableViewDataSource, UITableViewDelegate>

@property (nonatomic, weak) CZSlideView *slideView;

@end

@implementation GJHomeViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setupUI];
    
    _slideView.imageUrls = [self imageUrls];
    
}

/**
 *  图片轮播器图片假数据测试
 *
 *  @return 图片数组
 */
- (NSArray *)imageUrls {
    
    NSInteger count = 5;
    
    NSMutableArray *arrayM = [NSMutableArray array];
    
    for (NSInteger i = 0; i < count; i++) {
        // 1. 图像名称
        NSString *imageName = [NSString stringWithFormat:@"Home_Scroll_%02zd.jpg", (i + 1)];
        
        // 2. 创建 URL
        NSURL *url = [[NSBundle mainBundle] URLForResource:imageName withExtension:nil];
        
        // 3. 添加到数组
        [arrayM addObject:url];
    }
    
    return arrayM.copy;
}

#pragma mark - login监听
/**
 *  登录注册按钮
 */
- (void)login {
    NSLog(@"准备跳转登录/注册界面");
    
    UIStoryboard *loginSB = [UIStoryboard storyboardWithName:@"Login" bundle:nil];
    
    GJLoginViewController *vc = [loginSB instantiateViewControllerWithIdentifier:@"GG"];
    
    [self.navigationController pushViewController:vc animated:YES];
    
    self.tabBarController.tabBar.hidden = YES;
    
    
    
}

#pragma mark - UITableViewDelegate
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
    NSLog(@"%f", scrollView.contentOffset.x);
}

#pragma mark - UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 3;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)setupUI {
    //navBar的背景
    [self.navigationController.navigationBar setBarTintColor:[UIColor cz_colorWithHex:0x35AEF3]];
    //navBar的title
    self.navigationController.navigationBar.titleTextAttributes = @{NSForegroundColorAttributeName: [UIColor whiteColor], NSFontAttributeName: [UIFont systemFontOfSize:21]};
    //右侧barButtonItem
    UIBarButtonItem *loginItem = [[UIBarButtonItem alloc] initWithTitle:@"登录/注册" style:UIBarButtonItemStylePlain target:self action:@selector(login)];
    
    self.navigationItem.rightBarButtonItem = loginItem;
    [self.navigationItem.rightBarButtonItem setTintColor:[UIColor whiteColor]];
    [self.navigationItem.rightBarButtonItem setWidth:12];
    
    
    //首页tableView
    
    UITableView *tv = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStyleGrouped];
    
    
    [self.view addSubview:tv];
    
    [tv mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.view);
    }];
    
    
    [tv registerClass:[UITableViewCell class] forCellReuseIdentifier:cellId];
    
    tv.dataSource = self;
    tv.delegate = self;
    
    CZSlideView *v = [[CZSlideView alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, 212.5)];
    v.backgroundColor = [UIColor cyanColor];
    
    tv.tableHeaderView = v;
    tv.contentInset = UIEdgeInsetsMake(-44, 0, 0, 0);
    
    _slideView = v;
    
    
}

    NSLog(@"程东安测试");
    NSLog(@"测试");



}
@end
